<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="UTF-8">
        <title>订单确认 | <?php echo ($site_name_cn); ?>安全应急响应中心</title>
        <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
        <meta name="description" content="<?php echo ($site_name_cn); ?>安全应急响应中心,<?php echo ($site_name_en); ?> Security Response Center">
        <meta name="keywords" content="<?php echo ($site_name_cn); ?>,<?php echo ($site_name_en); ?>,安全团队,应急响应,<?php echo ($site_name_cn); ?>安全应急响应中心,<?php echo ($site_name_en); ?> Security Response Center">
        <meta name="renderer" content="webkit">
        <meta name="viewport" content="width=device-width, initial-scale=0.5, maximum-scale=0.5, minimum-scale=0.5, user-scalable=no">
        <link rel="icon" href="/Public/Index/images/logo.ico">
        <link rel="stylesheet" href="/Public/Index/css/main.css">
        <!--[if (gte IE 6)&(lte IE 8)]>
        兼容 CSS3 选择器
        <script type="text/javascript" src="/Public/Index/js/selectivizr.min.js"></script>
        兼容 media query
        <script type="text/javascript" src="/Public/Index/js/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <div class="header">
            <div>
                <div class="logo">
                    <a href="">
                        <div class="logo_pic">
                        </div>
                        <div class="logo_name">
							<p><?php echo ($site_name_cn); ?>安全应急响应中心</p>
                            <p><?php echo ($site_name_en); ?> Security Response Center</p>
                        </div>
                    </a>
                </div>

                <div class="userpanel">
                    <div class="userpanel_line">
                        <div></div>
                    </div>
                    <div class="userpanel_user">
                        <img class="user_avatar mod-avatar-30" src="/Public/Uploads/<?php echo session('avatar');?>" alt="">
                        <span class="user_username"><?php echo session('username'); if(session('mnum') == 0): else: ?><i class="i-header-message"><?php echo session('mnum');?></i><?php endif; ?></span>
                        <i class="user_arrow"></i>
                        <div class="user_menu">
                            <ul class="menu_list">
                                <li class="list_item list_item-user">
                                    <a href="<?php echo U('index/index');?>">
                                        <i class="item_icon"></i>
                                        <span class="item_text">个人主页</span>
                                    </a>
                                </li>
                                <li class="list_item list_item-message">
                                    <a href="<?php echo U('message/index');?>">
                                        <i class="item_icon"></i>
                                        <span class="item_text">消息中心</span>
                                        <i class="item_icon-message"><?php echo session('mnum');?></i>
                                    </a>
                                </li>
                                <li class="list_item list_item-account">
                                    <a href="<?php echo U('info/index');?>">
                                        <i class="item_icon"></i>
                                        <span class="item_text">账户设置</span>
                                    </a>
                                </li>
                                <li class="list_item list_item-logout">
                                    <a href="<?php echo U('login/logout');?>">
                                        <i class="item_icon"></i>
                                        <span class="item_text">注销</span>
                                    </a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>

                <div class="nav">
                    <ul>
                        <li class="[index_banner]"><a href="/index.php">首页</a></li>
                        <li class="[banner_selected]"><a href="<?php echo U('post/add');?>">提交漏洞</a></li>
                        <li class="[annoucment_banner]"><a href="/index.php?m=&c=page&a=index">公告</a></li>
						<li class="[blog_banner]"><a href="/index.php?m=&c=blog&a=index">博客</a></li>
						<li class="[hall_banner]"><a href="/index.php?m=&c=hall&a=index">贡献榜</a></li>
                        <li class="navselected"><a href="<?php echo U('gift/index');?>">礼品兑换</a></li>
                    </ul>
                </div>
            </div>
        </div>
        <div class="container container-shoporder">
            <div>
                <!-- section-subnav 标题-->
                <div class="section section-subnav">
                    <div class="section_subnav">
                        <p class="subnav_title">订单确认</p>
                    </div>
                </div>

                <div class="section section-orderpanel">
                    <div class="section_orderpanel">
                        <div class="orderpanel_check">
                            <div class="check_leftblock">
                                <div class="leftblock_pic">
                                    <img src="<?php echo ($gift["url"]); ?>" alt="">
                                </div>
                                <div class="leftblock_info">
                                    <h4><?php echo ($gift["title"]); ?></h4>
									<h3>库存：<?php echo ($gift["stock"]); ?> 个</h3>
                                </div>
                            </div>
                            <div class="check_rightblock">
                                <div class="rightblock_address">
                                    <h4 class="address_title">
                                        1. 选择收货地址
                                    </h4>
                                    <ul class="address_select">
										<?php if(is_array($info)): foreach($info as $key=>$v): if($v["default"] == 1): ?><li address="<?php echo ($v["id"]); ?>" id="address_<?php echo ($v["id"]); ?>" onclick="select_address('<?php echo ($v["id"]); ?>')" class="mod-address mod-address-added mod-address-added-default" select="selected" style="border-color:#007cfa;"><?php else: ?><li id="address_<?php echo ($v["id"]); ?>" onclick="select_address('<?php echo ($v["id"]); ?>')" address="<?php echo ($v["id"]); ?>" class="mod-address mod-address-added"><?php endif; ?>
                                            <p class="address_acceptor">
                                                <span class="acceptor_name"><?php echo ($v["realname"]); ?></span>
                                                <span class="acceptor_phone"><?php echo ($v["mobile"]); ?></span>
                                            </p>
                                            <p class="address_detail"><?php echo ($v["adetail"]); ?></p>
                                            <!--<div class="address_change">
                                                 <span class="change_setdefault">设为默认</span><a href="javascript:query_address(<?php echo ($v["id"]); ?>);"><i class="i-address-modify"></i></a> | <a href="javascript:delete_address(<?php echo ($v["id"]); ?>);"><i class="i-address-delete"></i></a>
                                            </div>-->
                                            <i class="i-mod-address-default"></i>
                                        </li><?php endforeach; endif; ?>
                                        
                                        <a href="<?php echo U('info/index');?>"><li class="mod-address mod-address-add">
                                            <i></i><span>添加新地址</span>
                                        </li></a>

                                    </ul>
                                </div>

                                <div class="rightblock_num">
                                    <h4 class="num_title">
                                        2. 确认兑换数量
                                    </h4>
                                    <div class="num_selectnum">
                                        <div class="mod-form-numselector">
                                            <a href="javascript:numminus();">
                                                -
                                            </a>
                                            <input id="redeemgoods" type="text" value="1">
                                            <a href="javascript:numplus();">
                                                +
                                            </a>
                                        </div>

                                        <span class="selectnum_calculate"> x <span class="calculate_unitprice"><span class="unitprice_num"><?php echo ($gift["price"]); ?></span> 安全币</span> = <span class="calculate_totalprice"><span id="total_price" class="totalprice_num"><?php echo ($gift["price"]); ?></span> 安全币</span></span>
                                    </div>

                                </div>

                            </div>
                        </div>
                        <div class="orderpanel_confirm">
                            <div class="confirm_leftblock">
                                <a class="mod-btn mod-btn-black" href="javascript:window.history.back();">返&nbsp;&nbsp;回</a>
                            </div>
                            <div class="confirm_rightblock">
                                <div class="rightblock_balance">
                                    <p class="balance_title">兑换后账户余额</p>
                                    <p class="balance_num">
                                        <span><?php echo ($account["jinbi"]); ?></span> - <span id ="confirm_total_price" ><?php echo ($gift["price"]); ?></span> = <span class="num_rest"><span id="left_account"><?php echo ($iniprice); ?> </span> 安全币</span>
                                    </p>
                                </div>
								<input id="user_token" type="hidden" value="<?php echo ($account["token"]); ?>">
                                <a class="mod-btn mod-btn-shop-orange" href="javascript:submit_my_order();">确认兑换</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
		<!--弹出层-->
		<div id="address_success" class="mod-popup mod-popup-report">
					<div class="popup_mask">
					</div>
					<div class="popup_body">
						<div class="body_content">
							<p class="content_title">兑换成功!</p>
							<p class="content_text">我们将会尽快为您发货，请耐心等待</p>
						</div>
						<div class="body_btns">
							<a class="mod-btn mod-btn-blue mod-btn-close" onclick="location.href='<?php echo U('gift/order');?>'">查看订单</a>
						</div>
						<i class="i-close" onclick="location.href='<?php echo U('gift/order');?>"></i>
					</div>
		</div>
		<div id="address_fail" class="mod-popup mod-popup-report">
					<div class="popup_mask">
					</div>
					<div class="popup_body">
						<div class="body_content">
							<p class="content_title">兑换失败!</p>
							<p class="content_text">兑换失败，请尝试重新提交。</p>
						</div>
						<div class="body_btns">
							<a class="mod-btn mod-btn-blue mod-btn-close" onclick="location.reload();">返回重试</a>
						</div>
						<i class="i-close" onclick="location.reload();"></i>
					</div>
		</div>
		<script>
			function submit_my_order(){
							var  user_token_val = $("#user_token").val();
							var  redeem_num_val = $("#redeemgoods").val();
							var  adress_id_val = $("li[select]").attr('address');
							$.ajax({
								url: "/user.php?m=user&c=gift&a=add",
								type: "POST",
								data: {token:user_token_val,gid:<?php echo ($gift["id"]); ?>,number:redeem_num_val,address:adress_id_val},
								success: function (data) {
									if (data.status == "1") {
										$("#address_success").css("display","block");
									}else{
										$("#address_fail").css("display","block");
									}
								},
								error: function () {
									$("#address_fail").css("display","block");
								}
							});
			}
			
		
			function select_address(adress_id){
				$("li[select]").css("border-color","#e6e6e6");
				$("li[select]").removeAttr('select');
				$("#address_" + adress_id).css("border-color","#007cfa");
				$("#address_" + adress_id).attr("select","selected");
				$("#address_" + adress_id).attr("id","selected_address");
			}
			
			function numplus(){
				var stock_num = <?php echo ($gift["stock"]); ?>;
				var single_price = <?php echo ($gift["price"]); ?>;
				var goodsnum = document.getElementById("redeemgoods");
				var total_price_element = document.getElementById("total_price");
				var confirm_total_price_element = document.getElementById("confirm_total_price");
				var left_account_element = document.getElementById("left_account");
				var resultnum = parseInt(goodsnum.value) + 1;
				var total_price = resultnum * single_price;
				var left_account = <?php echo ($account["jinbi"]); ?> - total_price; 
				var user_account_jinbi = <?php echo ($account["jinbi"]); ?>;
				if (resultnum > stock_num){
					alert('库存不足！');
				} else if(user_account_jinbi<total_price){
					alert('金币不足！');
				}else{
					goodsnum.value = resultnum;
					total_price_element.innerText = total_price;
					confirm_total_price_element.innerText = total_price;
					left_account_element.innerText = left_account;
				}
			}

			function numminus(){
				var single_price = <?php echo ($gift["price"]); ?>;
				var goodsnum = document.getElementById("redeemgoods"); 
				var total_price_element = document.getElementById("total_price");
				var confirm_total_price_element = document.getElementById("confirm_total_price");
				var left_account_element = document.getElementById("left_account");
				var resultnum = parseInt(goodsnum.value) - 1;
				var total_price = resultnum * single_price;
				var left_account = <?php echo ($account["jinbi"]); ?> - total_price; 
				if (resultnum > 0){
					goodsnum.value = resultnum;
					total_price_element.innerText = total_price;
					confirm_total_price_element.innerText = total_price;
					left_account_element.innerText = left_account;
				} else{
					alert('商品数量非法！');
				}
			}
		</script>

<!-- footer -->
        <div class="footer">
            <div>
                <div class="footer_about">
                    <p class="about_link">
                        <a href="<?php echo ($site_about); ?>" target="_blank">关于腾讯</a>
                        |
                        <a href="<?php echo ($site_career); ?>">加入我们</a>
                        |
                        <a href="/user.php?m=user&c=post&a=add">报告漏洞</a>
                    </p>
                    <p class="about_copyright">
                        <span>Copyright &copy; <?php echo date('Y'); ?> <?php echo ($site_copyright); ?>. All Rights Reserved</span>
						<span>Powered by <a href="https://security.tencent.com/index.php/xsrc">Tencent xSRC</a></span>
                    </p>
                </div>

                <div class="footer_contact">
                    <a class="contact_icon-email" href="mailto:<?php echo ($site_email); ?>"><i></i><span>专用邮箱</span>|</a>
                    <a class="contact_icon-weixin mod-qrcode" href="">
                        <i></i><span>微信公众号</span>
                        <div class="qrcode">
                            <div class="qrcode_pic">
                                <img src="<?php echo ($site_wechat); ?>" alt="">
                            </div>
                            <span class="qrcode_text">扫一扫关注公众号</span>
                        </div>
                    </a>
                </div>
            </div>
        </div>

        <script src="/Public/Index/js/jquery-1.7.2.min.js"></script>
        <script src="/Public/Index/js/test.js"></script>
		<script src="https://security.tencent.com/static/plugins/jquery.ajaxfileupload.js"></script>
    </body>
</html>